import {DynamicModule, Module} from "@nestjs/common";
import { TypeOrmModule } from "@nestjs/typeorm";
import { UserService } from "./services/user.service";
import { UserApiController } from "./api/user.api.controller";
import { UserEntity } from "./entities/user.entity";
import { ConfigModule, ConfigService } from "@nestjs/config";
import configuration from "../../src/config/configuration";
import { UserWebController } from "./web/user.web.controller";

@Module({

  imports:[
  // 注入全局配置文件
  // ConfigModule.forRoot({
  //   isGlobal: true,
  //   load: [configuration]
  // }),
  // TypeOrmModule.forRootAsync({
  //   imports: [ConfigModule],
  //   inject: [ConfigService],
  //   useFactory: async (configService: ConfigService) => ({
  //     ...configService.get("DATABASE_CONFIG")[0]
  //   }),
  //   }),
  ],
  providers:[UserService],
  controllers:[UserApiController,UserWebController],
  exports:[UserService]
})
export class SysModule {
  static config:Partial<Config> = {};

  static setConfig(config) {
    this.config = config;
    return this;
  }

  static forRoot():DynamicModule{
    return {
      module: this,
      global:true
    }
  }
}

export type Config = Record<"apiPath" | "adminPath", string>;
